using UnityEngine;

public class PlayerAIState_Offense_CrossOver : State<PlayerAI>
{
	public static PlayerAIState_Offense_CrossOver instance;

	private PlayerAIState_Offense_CrossOver()
	{
	}

	public static PlayerAIState_Offense_CrossOver getInstance()
	{
		if (instance == null)
		{
			instance = new PlayerAIState_Offense_CrossOver();
		}
		return instance;
	}

	public override void enter(PlayerAI owner)
	{
		base.exit(owner);
		if (owner.player.isSingleCrossOver)
		{
			owner.offense_crossover_time_wait = 0.2f;
			owner.offense_crossover_time_crossing = 0.2f;
		}
		else
		{
			owner.offense_crossover_time_wait = owner.player.team.time_think_at_offense;
			owner.offense_crossover_time_crossing = owner.player.team.time_crossover;
		}
		owner.offense_crossover_is_crossing = false;
	}

	public override void fixedUpdate(PlayerAI owner)
	{
		base.fixedUpdate(owner);
		if (owner.offense_crossover_count < 0)
		{
			owner.player.isSingleCrossOver = false;
			if (DSS.IsCanShoot(owner.player) && MathHelper.isInPercent(owner.player.team.percent_shoot_crossover_count_zero))
			{
				owner.do_offense_shoot();
			}
			else
			{
				owner.do_offense_pass();
			}
			return;
		}
		owner.offense_crossover_time_wait -= Time.fixedDeltaTime;
		if (owner.offense_crossover_time_wait <= 0f && !owner.offense_crossover_is_crossing)
		{
			owner.offense_crossover_is_crossing = true;
			owner.offense_crossover_count--;
			owner.turnDirection();
		}
		else
		{
			if (!owner.offense_crossover_is_crossing)
			{
				owner.player.do_dribble_stay();
			}
			if (!owner.offense_crossover_is_crossing && !DSS.IsSomeOneFront(owner.player.myTransform, owner.player.getParaTeam().getPlayer_ClosestToTarget(owner.player.getPosition()).getPosition()))
			{
				owner.do_offense_dribble();
			}
		}
		if (!owner.offense_crossover_is_crossing)
		{
			return;
		}
		if (owner.player.isSingleCrossOver)
		{
			owner.player.do_updownup();
			if (!owner.player.IsPlayingAnimation())
			{
				owner.do_offense_dribble();
			}
			return;
		}
		owner.player.do_dribble_run();
		GameHelper.MoveTo(owner.player, owner.player.getPosition() + owner.player.myTransform.forward, owner.player.getMoveSpeed(), isLookAtTargetPos: true);
		owner.offense_crossover_time_crossing -= Time.fixedDeltaTime;
		if (owner.offense_crossover_time_crossing <= 0f)
		{
			owner.do_offense_dribble();
		}
	}
}
